package com.jasonchoi.gateway;

import java.util.Objects;
import java.util.function.BiConsumer;

public class LamdbaUtils   {


  /**
   * lamdba foreach 可获取 index
   * Like  LamdbaUtils.forEach(list, (index, str) -> System.out.println(index + " -> " + str));
   * @param elements
   * @param action
   * @param <E>
   */
  public static <E> void forEach(
      Iterable<? extends E> elements, BiConsumer<Integer, ? super E> action) {
    Objects.requireNonNull(elements);
    Objects.requireNonNull(action);

    int index = 0;
    for (E element : elements) {
      action.accept(index++, element);
    }
  }
}
